package com.rgs.base.core.system;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum AsyncTaskStatusEnum {
    // 任务进行中
    RUNNING(1, "任务进行中"),
    SUCCEED(2, "任务成功"),
    FAILED(3, "任务失败"),
    CANCELED(4, "任务取消"),
    PART_SUCCEED(5, "部分成功"),

    UNKNOWN(404, "未知枚举"),
    ;

    private final int code;
    private final String status;

    /**
     * 根据code值获取对应的枚举
     *
     * @param code
     * @return
     */
    public static AsyncTaskStatusEnum getByCode(int code) {
        for (AsyncTaskStatusEnum item : values()) {
            if (item.getCode() == code) {
                return item;
            }
        }
        return UNKNOWN;
    }
}
